package com.ymatou.iapi.liveseller.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.DeleteModelBean;
import com.ymatou.iapi.liveseller.service.DeleteModelCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.livetv.Model;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
/**
*删除模特
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DeleteModel{
	private static DeleteModelBean deletemodelBean;
	private static DeleteModelCall deletemodelCall;
	LiveRoomWapper LiveRoomWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除模特");
	}

	@Before
	public void caseUp() {
		deletemodelBean=new DeleteModelBean();
		deletemodelCall=new DeleteModelCall();
		LiveRoomWapper=new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deletemodelCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DeleteModel_001() {
		Logger.start(true,"删除模特成功");
		try {
			int userid=1;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 1, "nick");
			deletemodelBean.setModelId(id);
			deletemodelBean.setUserId(userid);
			deletemodelCall.setData(deletemodelBean);
			deletemodelCall.callService();			
			Logger.verifyEquals("200", deletemodelCall.getString("Code"), "验证code");
			Model modle = LiveRoomWapper.selectModelById(id).get(0);
			Logger.verifyEquals(-1, modle.getAction(), "验证action");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteModel_002() {
		Logger.start(true,"不输入userid失败");
		try {
			deletemodelBean.setModelId(1);
//			deletemodelBean.setUserId(1);
			deletemodelCall.setData(deletemodelBean);
			deletemodelCall.callService();			
			Logger.verifyEquals("400", deletemodelCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteModel_003() {
		Logger.start(true,"不输入modelId失败");
		try {
//			deletemodelBean.setModelId(1);
			deletemodelBean.setUserId(1);
			deletemodelCall.setData(deletemodelBean);
			deletemodelCall.callService();			
			Logger.verifyEquals("400", deletemodelCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteModel_004() {
		Logger.start(true,"输入modelId和userid不匹配失败");
		try {
			deletemodelBean.setModelId(1);
			deletemodelBean.setUserId(1);
			deletemodelCall.setData(deletemodelBean);
			deletemodelCall.callService();			
			Logger.verifyEquals("201", deletemodelCall.getString("Code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteModel_005() {
		Logger.start(true,"输入不存在modelId失败");
		try {
			deletemodelBean.setModelId(999999);
			deletemodelBean.setUserId(1);
			deletemodelCall.setData(deletemodelBean);
			deletemodelCall.callService();			
			Logger.verifyEquals("201", deletemodelCall.getString("Code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteModel_006() {
		Logger.start(true,"重复调用删除");
		try {
			int userid=1;
			LiveRoomCallService.DeleteModel(userid);
			int id=LiveRoomCallService.CreateModelCall(userid, 1, 1, "nick");
			deletemodelBean.setModelId(id);
			deletemodelBean.setUserId(userid);
			deletemodelCall.setData(deletemodelBean);
			deletemodelCall.callService();		
			Logger.verifyEquals("200", deletemodelCall.getString("Code"), "验证code");
			deletemodelCall.callService();		
			Logger.verifyEquals("201", deletemodelCall.getString("Code"), "验证code");
			Model modle = LiveRoomWapper.selectModelById(id).get(0);
			Logger.verifyEquals(-1, modle.getAction(), "验证action");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}